<template>
  <div class="mask">
    <div class="drawer-wrap" :class="isLoaded ? 'visible' : ''" :style="`height: ${contentHeight + 72 + (footerVisible ? 84 : 0)}px`">
      <div class="drawer-header">
        <div class="text">{{ title }}</div>
        <n-icon size="32" style="cursor: pointer" @click="close">
          <CloseOutline />
        </n-icon>
      </div>
      <div class="drawer-content" :style="`height: ${contentHeight}px`">
        <slot name="content"></slot>
      </div>
      <div class="drawer-footer" v-if="footerVisible">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { CloseOutline } from '@vicons/ionicons5';
  import { onMounted, ref } from 'vue';

  type Props = {
    title: string;
    contentHeight: number;
    footerVisible: boolean;
  };

  const props = withDefaults(defineProps<Props>(), {
    title: '弹窗标题',
    footerVisible: true,
    contentHeight: 744,
  });

  const emits = defineEmits(['close']);
  function close() {
    emits('close');
  }
  const isLoaded = ref(false);
  onMounted(() => {
    isLoaded.value = true;
  });
</script>

<style scoped lang="less">
  .mask {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
  .drawer-wrap {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #fff;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    height: 0;
    transition: height 0.3s ease;
    overflow: hidden;
    &.visible {
      height: 900px;
    }
    .drawer-header {
      background-color: #fcf7f2;
      height: 72px;
      border-top-left-radius: 24px;
      border-top-right-radius: 24px;
      overflow: hidden;
      padding: 16px 36px;
      font-size: 24px;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .drawer-content {
      background-color: #fff;
      padding: 24px 36px;
      position: relative;
    }
    .drawer-footer {
      background-color: #fff;
      height: 84px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      border-top: 1px solid #e6eaed;
      ::v-deep(.n-button) {
        font-size: 24px;
        width: 132px;
        height: 60px;
        border-radius: 12px;
        margin: 0 10px;
      }
    }
  }
</style>
